package wifiunion.com.notice.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;


import java.util.ArrayList;
import java.util.List;

import wifiunion.com.notice.R;
import wifiunion.com.notice.RecyclerItemClick;
import wifiunion.com.notice.entity.DeviceSelectSth;
import wifiunion.com.notice.viewholder.DeviceSelectSthViewHolder;

/**
 * Created by Administrator on 2016/12/5.
 */

public class DeviceSelectSthAdapter extends RecyclerView.Adapter<DeviceSelectSthViewHolder> {


    private Context mContext;

    private List<DeviceSelectSth> mData = new ArrayList<>();

    public RecyclerItemClick mItemCheck;


    private int mType = 0;


    public DeviceSelectSthAdapter(Context context, List<DeviceSelectSth> data, RecyclerItemClick itemCheck) {
        mContext = context;
        mData = data;
        mItemCheck = itemCheck;
    }

    public DeviceSelectSthAdapter(Context context, List<DeviceSelectSth> data, RecyclerItemClick itemCheck, int type) {
        mContext = context;
        mData = data;
        mItemCheck = itemCheck;
        mType = type;
    }

    @Override
    public DeviceSelectSthViewHolder onCreateViewHolder(ViewGroup parent,int position) {


        View view;
        if (mType == 0) {
            view = LayoutInflater.from(parent.getContext()).inflate(R.layout.child_device_group_item, parent, false);
        } else {
            view = LayoutInflater.from(parent.getContext()).inflate(R.layout.dialog_video_item, parent, false);
        }
        DeviceSelectSthViewHolder viewHolder = new DeviceSelectSthViewHolder(view, mItemCheck);

        return viewHolder;
    }

    public void setOnclickListener(RecyclerItemClick click){
        mItemCheck = click;
    }

    @Override
    public void onBindViewHolder( DeviceSelectSthViewHolder holder, final int position) {


        if (mData.get(position).isSelected()) {
            holder.mCheckbox.setSelected(true);
        } else {
            holder.mCheckbox.setSelected(false);
        }

        holder.mCheckbox.setTag(position);


        holder.nameTv.setText(TextUtils.isEmpty(mData.get(position).getName()) ? "":mData.get(position).getName());

    }

    @Override
    public int getItemCount() {
        return mData.size();
    }
}
